home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / Printer / src / Okimate20 / transfer.c < prev   
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.8 KB  |  117 lines

  1. /*
  2.     Transfer routine for Okimate_20.
  3.     David Berezowski - October/87.
  4.  
  5.   Copyright (c) 1988 Commodore-Amiga, Inc.
  6.  
  7.   Executables based on this information may be used in software
  8.   for Commodore Amiga computers.  All other rights reserved.
  9.  
  10.   This information is provided "as is"; no warranties are made.
  11.   All use is at your own risk, and no liability or responsibility is assumed.
  12. */
  13.  
  14.  
  15. #include <exec/types.h>
  16. #include "../printer/printer.h"
  17. #include "../printer/prtbase.h"
  18. #include "../printer/prtgfx.h"
  19.  
  20. Transfer(PInfo, y, ptr, colors)
  21. struct PrtInfo *PInfo;
  22. UWORD y;    /* row # */
  23. UBYTE *ptr;    /* ptr to buffer */
  24. UWORD *colors; /* indexes to color buffers */
  25. {
  26.     extern struct PrinterData *PD;
  27.  
  28.     static UWORD bit_table[8] = {128, 64, 32, 16, 8, 4, 2, 1};
  29.     union colorEntry *ColorInt;
  30.     UBYTE *dmatrix, *yptr, *mptr, *cptr, y24, bit;
  31.     UBYTE dvalue, Yellow, Magenta, Cyan, threshold;
  32.     UWORD x, x3, width, sx, *sxptr;
  33.  
  34.     /* pre-compute */
  35.     /* printer non-specific, MUST DO FOR EVERY PRINTER */
  36.     x = PInfo->pi_xpos;
  37.     ColorInt = PInfo->pi_ColorInt;
  38.     sxptr = PInfo->pi_ScaleX;
  39.     width = PInfo->pi_width;
  40.     /* pre-compute ptr to dither matrix */
  41.     dmatrix = PInfo->pi_dmatrix + ((y & 3) << 2);
  42.  
  43.     /* printer specific */
  44.     bit = bit_table[y & 7];
  45.     y24 = (y % 24) >> 3;
  46.  
  47.  
  48.     if (PD->pd_Preferences.PrintShade == SHADE_COLOR) {
  49.         yptr = ptr + y24 + colors[0];
  50.         mptr = ptr + y24 + colors[1];
  51.         cptr = ptr + y24 + colors[2];
  52.         x3 = x * 3;
  53.         do { /* for all source pixels */
  54.             /* compute intensity values for each color component */
  55.             Yellow = ColorInt->colorByte[PCMYELLOW];
  56.             Magenta = ColorInt->colorByte[PCMMAGENTA];
  57.             Cyan = ColorInt->colorByte[PCMCYAN];
  58.             ColorInt++;
  59.  
  60.             sx = *sxptr++;
  61.  
  62.             do { /* use this pixel 'sx' times */
  63.                 dvalue = dmatrix[x & 3];
  64.                 if (Yellow > dvalue) {
  65.                     *(yptr + x3) |= bit;
  66.                 }
  67.                 if (Magenta > dvalue) {
  68.                     *(mptr + x3) |= bit;
  69.                 }
  70.                 if (Cyan > dvalue) {
  71.                     *(cptr + x3) |= bit;
  72.                 }
  73.                 ++x; /* done 1 more printer pixel */
  74.                 x3 += 3;
  75.             } while (--sx);
  76.         } while (--width);
  77.     }
  78.     else { /* b&w or grey_scale printout */
  79.         ptr += y24+ colors[0];
  80.         /* are we thresholding? */
  81.         if (threshold = PInfo->pi_threshold) {
  82.             /* yes, so pre-compute dither value */
  83.             dvalue = threshold ^ 15;
  84.             do { /* for all source pixels */
  85.                 Yellow = ColorInt->colorByte[PCMBLACK];
  86.                 ColorInt++;
  87.  
  88.                 sx = *sxptr++;
  89.  
  90.                 do { /* use this pixel 'sx' times */
  91.                     if (Yellow > dvalue) {
  92.                         *ptr |= bit;
  93.                     }
  94.                     ptr += 3;
  95.                 } while (--sx);
  96.             } while (--width);
  97.         }
  98.         else { /* greyscale */
  99.             do { /* for all source pixels */
  100.                 Yellow = ColorInt->colorByte[PCMBLACK];
  101.                 ColorInt++;
  102.  
  103.                 sx = *sxptr++;
  104.  
  105.                 do { /* use this pixel 'sx' times */
  106.                     dvalue = dmatrix[x & 3];
  107.                     if (Yellow > dvalue) {
  108.                         *ptr |= bit;
  109.                     }
  110.                     ptr += 3;
  111.                     ++x; /* done 1 more printer pixel */
  112.                 } while (--sx);
  113.             } while (--width);
  114.         }
  115.     }
  116. }
  117.